﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.OleDb;
using Oracle.DataAccess.Client;
//using System.Data.OracleClient;
using _3TierDemo.DTO;
namespace _3TierDemo.DAL
{
    class LopDAO : CommonDAO
    {
        public LopDAO()
            : base()
        { }
        public DataTable getAll()
        {
            string strSelect = "select * from tblLop";
            return execSelect(strSelect);
        }
        public LopDTO getByID(int id)
        {
            string strSelect = "select * from tblLop where ma =" + id.ToString();            
            DataTable dt = new DataTable();
            dt = execSelect(strSelect);
            //map vao doi tuong
            LopDTO obj = new LopDTO();
            obj.Ma = Convert.ToInt32(dt.Rows[0][0]);
            obj.Ten= dt.Rows[0][1].ToString();
            obj.TenGV = dt.Rows[0][2].ToString();
            return obj;

        }
        public bool insert(LopDTO obj)
        {
            string strQuery = "insert into tblLop values ("+obj.Ma+",'" + obj.Ten + "','" + obj.TenGV + "')";
            return execNonQuery(strQuery);

        }
        public bool update(LopDTO obj)
        {
            string strQuery = "update tblLop set ten='" + obj.Ten + "',tengv='" + obj.TenGV + "' where ma=" + obj.Ma;
            return execNonQuery(strQuery);
        }
        public bool deleteByID(int id)
        {
            string strQuery = "delete from tblLop where ma=" + id.ToString();
            return execNonQuery(strQuery);
        }
    }
}
